<template>
  <el-form ref="formRef" :model="formData" :rules="formRules" label-width="120px">
    <el-row>
      <el-col :span="4">
        <div class="flex items-center justify-center !h-full">
          <UploadImg v-model="formData.avatar" :disabled="false" width="150px" height="150px">
            <template #tip>
              <el-text>请上传头像</el-text>
            </template>
          </UploadImg>
        </div>
      </el-col>
      <el-col :span="20">
        <el-row>
          <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
            <el-form-item label="姓名" prop="familyName">
              <el-input v-model="formData.familyName" placeholder="请输入姓名" />
            </el-form-item>
          </el-col>
          <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
            <el-form-item label="昵称" prop="nickname">
              <el-input v-model="formData.nickname" />
            </el-form-item>
          </el-col>
          <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
            <el-form-item label="性别" prop="sex">
              <el-select v-model="formData.sex" placeholder="请选择">
                <el-option
                  v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_USER_SEX)"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
            <el-form-item label="学历" prop="education">
              <el-select v-model="formData.education" placeholder="请选择">
                <el-option
                  v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_USER_EDUCATION)"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>

          <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
            <el-form-item label="手机号码" prop="mobile">
              <el-input
                v-model="formData.mobile"
                maxlength="11"
                @blur="testMobile"
                placeholder="请输入手机号码"
              />
            </el-form-item>
          </el-col>
          <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
            <el-form-item label="登录账号" prop="username">
              <el-input v-model="formData.username" disabled placeholder="请输入登录账号">
                <template #append>默认手机号</template>
              </el-input>
            </el-form-item>
          </el-col>
          <!-- <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
            <el-form-item label="邮箱地址" prop="email">
              <el-input v-model="formData.email" maxlength="50" placeholder="请输入邮箱" />
            </el-form-item>
          </el-col> -->
          <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
            <el-form-item label="婚姻状况" prop="marital">
              <el-select v-model="formData.marital" placeholder="请选择">
                <el-option
                  v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_USER_MARRIAGE)"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
            <el-form-item label="身份证号" prop="idNum">
              <el-input v-model="formData.idNum" maxlength="18" placeholder="请输入身份证号" />
            </el-form-item>
          </el-col>
          <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
            <el-form-item label="生日" prop="userBirthday">
              <el-input
                v-model="formData.userBirthday"
                @blur="calculateAge"
                placeholder="请输入格式为YYYY-MM-DD的生日"
              >
                <template #append>
                  <el-checkbox label="农历" v-model="formData.isLunar" />
                </template>
              </el-input>
              <!-- <div class="flex">
                <el-date-picker
                  class="!w-full"
                  v-model="formData.userBirthday"
                  @change="calculateAge"
                  type="date"
                  value-format="YYYY-MM-DD"
                  placeholder="选择出生日期"
                />
                <el-checkbox class="pl-15px flex-1" v-model="formData.isLunar"
                  ><span>农历</span>
                </el-checkbox>
              </div> -->
            </el-form-item>
          </el-col>
          <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
            <el-form-item label="年龄" prop="userAge">
              <el-input v-model="formData.userAge" disabled />
            </el-form-item>
          </el-col>
          <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
            <el-form-item label="民族" prop="userNationalities">
              <el-select v-model="formData.userNationalities" placeholder="请选择">
                <el-option
                  v-for="dict in nationList"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
            <el-form-item label="政治面貌" prop="userPolitical">
              <el-select v-model="formData.userPolitical" placeholder="请选择">
                <el-option
                  v-for="dict in getIntDictOptions(DICT_TYPE.SYSTEM_USER_POLITICSSTATUS)"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8" v-if="formData.id === undefined">
            <el-form-item label="密码" prop="password">
              <el-input
                v-model="formData.password"
                placeholder="请输入密码"
                show-password
                :disabled="systemDefault"
                autocomplete="new-password"
                type="password"
              >
                <template #append>
                  <el-checkbox label="系统默认" v-model="systemDefault" />
                </template>
              </el-input>
            </el-form-item>
          </el-col>
          <el-col :xs="8" :sm="8" :md="8" :lg="8" :xl="8">
            <el-form-item label="账号状态" prop="status">
              <el-radio-group v-model="formData.status">
                <el-radio
                  v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
                  :key="dict.value"
                  :value="dict.value"
                >
                  {{ dict.label }}
                </el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-col>
    </el-row>
  </el-form>
</template>
<script lang="ts" setup>
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'

import * as UserApi from '@/api/system/user'

import { FormRules } from 'element-plus'
import { copyValueToTarget } from '@/utils'
import { propTypes } from '@/utils/propTypes'

defineOptions({ name: 'SystemUserForm' })
const props = defineProps({
  propFormData: {
    type: Object as PropType<UserApi.UserVO>,
    default: () => {}
  },
  activeName: propTypes.string.def('tenant')
})
const calculateAge = () => {
  if (!formData.userBirthday) {
    return
  }
  const today = new Date()
  // const birthDate = formatDate(formData.userBirthday, 'YYYY-MM-DD')

  const birthDateParsed = new Date(formData.userBirthday)
  let age = today.getFullYear() - birthDateParsed.getFullYear()
  const monthDifference = today.getMonth() - birthDateParsed.getMonth()

  if (
    monthDifference < 0 ||
    (monthDifference === 0 && today.getDate() < birthDateParsed.getDate())
  ) {
    age--
  }
  formData.userAge = age.toString()
  console.log(age)
  return age
}
const nationList = ref([
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 135,
    dictSort: 1,
    label: '汉族',
    value: '1',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'primary',
    isDefault: 'Y',
    status: '0',
    default: true
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 136,
    dictSort: 2,
    label: '壮族',
    value: '2',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'success',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 137,
    dictSort: 3,
    label: '回族',
    value: '3',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'info',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 138,
    dictSort: 4,
    label: '满族',
    value: '4',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'primary',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 139,
    dictSort: 5,
    label: '维吾尔族',
    value: '5',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'success',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 140,
    dictSort: 6,
    label: '苗族',
    value: '6',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'info',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 141,
    dictSort: 7,
    label: '彝族',
    value: '7',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'warning',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 142,
    dictSort: 8,
    label: '土家族',
    value: '8',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'danger',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 143,
    dictSort: 9,
    label: '藏族',
    value: '9',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'primary',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 144,
    dictSort: 10,
    label: '蒙古族',
    value: '10',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'success',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 145,
    dictSort: 11,
    label: '侗族',
    value: '11',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'info',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 146,
    dictSort: 12,
    label: '布依族',
    value: '12',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'primary',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 147,
    dictSort: 13,
    label: '瑶族',
    value: '13',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'success',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 148,
    dictSort: 14,
    label: '白族',
    value: '14',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'info',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 149,
    dictSort: 15,
    label: '朝鲜族',
    value: '15',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'warning',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 150,
    dictSort: 16,
    label: '哈尼族',
    value: '16',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'danger',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 151,
    dictSort: 17,
    label: '黎族',
    value: '17',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'primary',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 152,
    dictSort: 18,
    label: '哈萨克族',
    value: '18',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'success',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 153,
    dictSort: 19,
    label: '傣族',
    value: '19',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'info',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 154,
    dictSort: 20,
    label: '畲族',
    value: '20',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'primary',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 155,
    dictSort: 21,
    label: '傈僳族',
    value: '21',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'success',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 156,
    dictSort: 22,
    label: '东乡族',
    value: '22',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'info',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 157,
    dictSort: 23,
    label: '仡佬族',
    value: '23',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'warning',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 158,
    dictSort: 24,
    label: '拉祜族',
    value: '24',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'danger',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 159,
    dictSort: 25,
    label: '佤族',
    value: '25',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'primary',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 160,
    dictSort: 26,
    label: '水族',
    value: '26',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'success',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 161,
    dictSort: 27,
    label: '纳西族',
    value: '27',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'info',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 162,
    dictSort: 28,
    label: '羌族',
    value: '28',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'primary',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 163,
    dictSort: 29,
    label: '土族',
    value: '29',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'success',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 164,
    dictSort: 30,
    label: '仫佬族',
    value: '30',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'info',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 165,
    dictSort: 31,
    label: '锡伯族',
    value: '31',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'warning',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 166,
    dictSort: 32,
    label: '柯尔克孜族',
    value: '32',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'danger',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 167,
    dictSort: 33,
    label: '景颇族',
    value: '33',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'primary',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 168,
    dictSort: 34,
    label: '达斡尔族',
    value: '34',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'success',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 169,
    dictSort: 35,
    label: '撒拉族 ',
    value: '35',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'info',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 170,
    dictSort: 36,
    label: '布朗族',
    value: '36',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'primary',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 171,
    dictSort: 37,
    label: '毛南族',
    value: '37',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'success',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 172,
    dictSort: 38,
    label: '塔吉克族',
    value: '38',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'info',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 173,
    dictSort: 39,
    label: '普米族',
    value: '39',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'warning',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 174,
    dictSort: 40,
    label: '阿昌族',
    value: '40',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'danger',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 175,
    dictSort: 41,
    label: '怒族',
    value: '41',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'primary',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 176,
    dictSort: 42,
    label: '鄂温克族',
    value: '42',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'success',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 177,
    dictSort: 43,
    label: '京族',
    value: '43',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'info',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 178,
    dictSort: 44,
    label: '基诺族',
    value: '44',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'primary',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 179,
    dictSort: 45,
    label: '德昂族',
    value: '45',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'success',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 180,
    dictSort: 46,
    label: '保安族',
    value: '46',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'info',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 181,
    dictSort: 47,
    label: '俄罗斯族',
    value: '47',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'warning',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 182,
    dictSort: 48,
    label: '裕固族',
    value: '48',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'danger',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 183,
    dictSort: 49,
    label: '乌孜别克族',
    value: '49',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'primary',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 184,
    dictSort: 50,
    label: '门巴族',
    value: '50',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'success',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 185,
    dictSort: 51,
    label: '鄂伦春族',
    value: '51',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'info',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 186,
    dictSort: 52,
    label: '独龙族',
    value: '52',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'primary',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 187,
    dictSort: 53,
    label: '赫哲族',
    value: '53',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'success',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 188,
    dictSort: 54,
    label: '高山族',
    value: '54',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'info',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 189,
    dictSort: 55,
    label: '珞巴族',
    value: '55',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'warning',
    isDefault: 'N',
    status: '0',
    default: false
  },
  {
    searchValue: null,
    createBy: 1,
    createTime: '2022-09-23 21:48:33',
    updateBy: null,
    updateTime: null,
    remark: null,
    ccedList: null,
    sysAttachmentList: null,
    params: {},
    dictCode: 190,
    dictSort: 56,
    label: '塔塔尔族',
    value: '56',
    dictType: 'nation_list',
    cssClass: null,
    listClass: 'danger',
    isDefault: 'N',
    status: '0',
    default: false
  }
])
const message = useMessage() // 消息弹窗
const testMobile = () => {
  if (formData.mobile != '' && !formData.id) {
    UserApi.getValidationMobile({ mobile: formData.mobile })
  }
}
const systemDefault = ref(true)
const formData = reactive({
  avatar: '',
  familyName: '',
  nickname: '',
  deptId: '',
  mobile: '',
  education: undefined,
  marital: undefined,
  email: '',
  idNum: '',
  id: undefined,
  userAge: '',
  isLunar: 0,
  username: '',
  password: '',
  sex: undefined,
  userBirthday: undefined,
  userNationalities: undefined,
  userPolitical: undefined,
  // userSource: undefined,
  status: undefined
})
const formRules = reactive<FormRules>({
  familyName: [{ required: true, message: '姓名不能为空', trigger: 'blur' }],
  // password: [{ required: true, message: '密码不能为空', trigger: 'blur' }],
  // deptId: [{ required: true, message: '归属部门不能为空', trigger: 'change' }],
  email: [
    {
      type: 'email',
      message: '请输入正确的邮箱地址',
      trigger: ['blur', 'change']
    }
  ],
  mobile: [
    { required: true, message: '手机号码不能为空', trigger: 'blur' },
    {
      pattern: /^(?:(?:\+|00)86)?1(?:3[\d]|4[5-79]|5[0-35-9]|6[5-7]|7[0-8]|8[\d]|9[189])\d{8}$/,
      message: '请输入正确的手机号码',
      trigger: 'blur'
    }
  ],
  // idNum: [
  //   { required: true, message: '身份证号码不能为空', trigger: 'blur' },
  //   {
  //     pattern:
  //       /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/,
  //     message: '请输入正确的身份证号码',
  //     trigger: 'blur'
  //   }
  // ],
  // postIds: [{ required: true, message: '岗位不能为空', trigger: 'change' }],
  sex: [{ required: true, message: '性别不能为空', trigger: 'change' }]
})
const formRef = ref() // 表单 Ref
/** 表单校验 */
const validate = async () => {
  if (!formRef) return
  try {
    await unref(formRef)?.validate()
    console.log(formData)

    // 校验通过更新数据
    Object.assign(props.propFormData, formData)
    console.log(props.propFormData)
  } catch (e) {
    message.error('【基础信息】不完善，请填写相关信息')
    throw e // 目的截断之后的校验
  }
}
const setStatus = (status: any) => {
  formData.status = status
}
defineExpose({ validate, setStatus })

/** 将传进来的值赋值给 formData */
watch(
  () => props.propFormData,
  (data) => {
    if (!data) {
      return
    }
    copyValueToTarget(formData, data)
  },
  {
    immediate: true
  }
)
onMounted(async () => {})
</script>
